package ru.aptu.gsp_banking.domain;

import javax.persistence.*;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * Created by IntelliJ IDEA.
 * User: alex
 * Date: 11/23/11
 * Time: 5:56 PM
 */

@Entity
@Table(name = "transactions")
public class Transaction {
    /*
    id int not null auto_increment primary key,
    account_id int not null,
    amount float not null,
    currency char(3) not null,
    amount_in_account_cur float not null,
    account_cur char(3) not null,
    datetime date not null,
    description varchar(300) null,
     */

    @Id
	@Column(name = "id")
	@GeneratedValue
	private Integer id;

    @Column(name = "account_id")
	private Integer accountId;

    @Column(name = "amount")
	private float amount;

    @Column(name = "currency")
    private String currency;

    @Column(name = "amount_in_account_cur")
	private float amountInAccountCur;

    @Column(name = "account_cur")
    private String accountCur;

    @Column(name = "datetime")
	private Date datetime;

    @Column(name = "description")
    private String description;

    public Transaction() {

    }

    public Transaction(Integer accountId, float amount, String currency, String description) {
        this.accountId = accountId;
        this.amount = amount;
        this.currency = currency;
        this.description = description;
    }

    public float getAmount() {
        return amount;
    }

    public String getFullAmount() {
        return (new Float(amount)).toString() + " " + currency;
    }

    public void setAmount(float amount) {
        this.amount = amount;
    }

    public String getCurrency() {
        return currency;
    }

    public void setCurrency(String currency) {
        this.currency = currency;
    }

    public float getAmountInAccountCur() {
        return amountInAccountCur;
    }

    public void setAmountInAccountCur(float amountInAccountCur) {
        this.amountInAccountCur = amountInAccountCur;
    }

    public String getFullAmountInAccountCur() {
        return (new Float(amountInAccountCur)).toString() + " " + accountCur;
    }

    public String getAccountCur() {
        return accountCur;
    }

    public void setAccountCur(String accountCur) {
        this.accountCur = accountCur;
    }

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public Integer getAccountId() {
        return accountId;
    }

    public void setAccountId(Integer accountId) {
        this.accountId = accountId;
    }

    public Date getDatetime() {
        return datetime;
    }

    public void setDatetime(Date datetime) {
        this.datetime = datetime;
    }

    public String getFormattedDatetime() {
        DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        return dateFormat.format(datetime);
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    public boolean equals(Object o) {
        return o instanceof Transaction && ((Transaction)o).getAccountId() == accountId &&
            ((Transaction)o).getAmount() == amount && ((Transaction)o).getCurrency() == currency;
    }
}
